package com.example.chapter03;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.chapter03.util.DateUtil;

public class ButtonEnableActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn_text;
    private TextView tv_result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_enable);
        Button btn_enable = findViewById(R.id.btn_enable);
        Button btn_disenable = findViewById(R.id.btn_disenable);
        btn_text = findViewById(R.id.btn_text);
        tv_result = findViewById(R.id.tv_result);
        btn_enable.setOnClickListener(this);
        btn_disenable.setOnClickListener(this);
        btn_text.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_enable) {
            btn_text.setEnabled(true);
        } else if (view.getId() == R.id.btn_disenable) {
            btn_text.setEnabled(false);
        } else if (view.getId() == R.id.btn_text) {
            String desc = String.format("%s 您点击了按钮： %s", DateUtil.getNowTime(), ((Button) view).getText());
            tv_result.setText(desc);
        }
    }
}